Hive Metastore 3.0

适用于版本>=3.0,其他版本详见Metastore Administration

Metastore保存有Hive对象定义(数据库、表和函数等),以及系统配置、统计和授权记录等。Hive和执行引擎在运行时访问这些数据,以决定解析、授权和查询的方式。

Hive通过DataNucleus(一种基于JDO的Java对象关系映射(ORM)层)持久化对象定义到关系型数据库中。

Metastore可以使用内嵌的Derby或外部数据库。可整个内嵌到用户进程,或者作为服务运行。

1 Hive 2 与Hive 3变化

Hive 3允许Metastore以独立的进程运行。为了保持兼容性,以前的配置依旧有效,并且新增了一些功能和配置。独立运行Metastore,详见Running the Metastore Without Hive

2 通用配置

Metastore可以通过以下配置:

  • $METASTORE_HOME/conf/metastore-site.xml(仅限Hive 3)
  • HIVE_HOME/conf/hive-site.xml或hive-metastoresite.xml
  • 命令行

以下为常用的配置,不常用的配置,详见 Less Commonly Changed Configuration Parameters

image-20200611220246842

3 RDBMS

(1) 内嵌Derby

默认配置,用于测试。每次只允许一个客户端。由于使用的是内存版本,客户端生命周期结束后不会持久化。

(2) 外部

适用于持久化和多终端用途。Metastore通过JDBC与RDBMS连接。

JDBC驱动需要放置在 METASTORE_HOME/lib下,或命令行显式传递。

下表配置不区分版本:

image-20200611222336112

(3) 支持的RDBMS

由于Hive使用DataNucleus与RDBMS通信。理论上,支持所有与DataNucleus兼容的RDBMS。以下为经过测试的:

image-20200611222805785

注意:

SCHEMA为Metastore存储表的数据库或schema。

Oracle配置针对轻JDBC客户端,其他客户端有所区别。

Postgres需要关闭metastore.try.direct.sql.ddl (或之前的hive.metastore.try.direct.sql.ddl)

(4) Schema安装和升级

schematool用于管理schema,详见help选项。通常schematool从metastore-site.xml或命令行获取配置。

  • -initSchema: install a new schema. This should be used when first setting up a Metastore.
  • -upgradeSchema: upgrade to the newly installed version. For 3.0, upgrades can be done from 1.2, 2.0, 2.1, 2.2, and 2.3 to 3.0. If you need to upgrade from before 1.2, use an older version of Hive’s schematool to first upgrade your schema to 1.2, then use the current Metastore version to upgrade to 3.0.
  • -createUser: create the Metastore user and schema. This does not install the tables, it just creates the database user and schema. This likely will not work in a production environment because you likely will not have permissions to create users and schemas. You will likely need your DBA to do this for you.
  • -validate: check that your Metastore schema is correct for its recorded version

4 运行Metastore

(1) 内嵌模式

以库形式在内嵌到用户进程中。默认在没有配置metastore.uris使用,不建议在生产环境中使用。

由于可能有多个客户端,大量的连接对DBMS是负担,并且多个客户端同时读写,难以保证数据安全。

(2) 服务模式

单独运行前,需要配置以下URL:

image-20200611224446177

注意:

启动Metastore,使用start-metastore命令。

停止则直接杀掉进程。

1)高可用

Metastore服务是无状态的。可以通过启用多个服务提供高可用特性,同时可以配置部分客户端使用内嵌的Metastore。

在客户端上,配置metastore.thrift.uris(逗号分隔的列表)和metastore.thrift.uri.selection ((Hive 2) hive.metastore.uri.selection)为RANDOM或SEQUENTIAL。

2) 安全

TODO: Need to fill in details for setting up with Kerberos, SSL, etc.

CLIENT_KERBEROSPRINCIPAL, KERBEROS, SSL, USE_SSL, USE_THRIFT_SASL

5 不依靠Hive运行

版本>=3.0

需要修改为以下属性:

Configuration Parameter Set to for Standalone Mode
metastore.task.threads.always org.apache.hadoop.hive.metastore.events.EventCleanerTask,org.apache.hadoop.hive.metastore.MaterializationsCacheCleanerTask
metastore.expression.proxy org.apache.hadoop.hive.metastore.DefaultPartitionExpressionProxy

注意:此模式下

ACID表不能压缩

副本机制没有测试

6 性能优化

(1) CacheStore

Hive 3之前只有一种API实现ObjectStore。HIVE-16520引入了缓存对象到内存中的实现。可以提高来回操作数据库的效率。通过配置metastore.rawstore.impl为ache.hadoop.hive.metastore.cache.CachedStore

MetaStore导致数据变化时自动更新(默认频率1分钟),可以避免多个服务间的数据不一致。

详见 Configuration Properties (Prefix: metastore.cached)

7 不常变化配置参数

BATCHEDRETRIEVE, CLIENT_CONNECT_RETRY_DELAY, FILTER_HOOK, SERDES_USING_METASTORE_FORSCHEMA, SERVER_THREADS,

THREAD_POOL_SIZE

Security: EXECUTE_SET_UGI, metastore.authorization.storage.checks

Setting up Caching: CACHED, CATALOGS_TO_CACHE & AGGREGATE_STATS_CACHE

Transactions: MAX_OPENTXNS, TXNS*

参考资料

AdminManual Metastore 3.0 Administration

CentOS7+ Hadoop3.2.0+MySQL5.7安装配置Hive3.1.1

XML中的&使用